#ifndef SDFMANAGER_H
#define SDFMANAGER_H

#include <BulletLibDefine.h>
#include <SDF.h>
#include <string>
#include <map>
#include <osg/Vec3>
#include <QString>
#include <QStringList>
#include <SDFContact.h>
#include <osg/Group>
class BULLET_EDITOR_DLL SDFManager
{
public:
    static SDFManager* instance();
    ~SDFManager();

    osg::ref_ptr<SDF> getSDF(int ptrInt);

    void readFromFile(const std::string& fileName);//read a xml file;
    void addPtrActualToptr(int ptrActual, int ptr);
    int getPtr(int ptrActual);

    void clearSDFContacts();//called when perform collision check
    void addSDFContact(osg::ref_ptr<SDFContact> sdfContact);
    int getSDFContactsCount();

    osg::ref_ptr<osg::Node> getContactDebugDrawerNode();
    void updateContactDebugDrawerNode();

    void computeSDFDofAll();

    void computeDisassemblySequenceAll();

    void computeSDFDOf(osg::ref_ptr<SDF> sdfPtr);
    void printContacts();
    void saveContactsToMatlabInputFile(osg::ref_ptr<SDF> sdfPtr);
protected:
    std::vector<osg::ref_ptr<SDFContact>> findContactOfSDF(osg::ref_ptr<SDF> sdfPtr);
    QStringList computeDisassemblySequence();
    osg::Vec3 strToVec3(const QString& strValue);
    void recoveAllSDFCollisionEnable();
    void printDisassemblySequence();
private:
    SDFManager();
    static SDFManager* _instance;
    std::vector<osg::ref_ptr<SDF>> m_sdfVector;
    std::map<int, int> m_ptrActualToptr;
    std::vector<osg::ref_ptr<SDFContact>> m_sdfContacts;
    osg::ref_ptr<osg::Group> m_contactDebugDrawerNode;

    std::vector<QStringList> m_disassemblySequence;
};

#endif // SDFMANAGER_H
